<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>注册页面</title>
    <link rel="stylesheet" href="css/reg.css">
</head>

<body>
    <header>
        <div id="box">
            <span> <img src="assets/images/HUAWEI.svg" class="adHeadPic"
                    style="height: 24px;width:108px;margin-top: 0px;">
            </span>
            <span><a href="index.html">华为商城</a> </span>
        </div>
    </header>
    <section>
        <h2>用户注册</h2>
        <div id="infor">
            <form id="login">
                <div class="regbox">
                    <p class="username">
                        <label>用户名：</label>
                        <input type="text" name="username" id="newUser">
                    </p>
                    <p class="phonenum">
                        <label for="newUser">手机号：</label>
                        <input type="text" id="phone" name="phonenum">
                    </p>
                    <p class="password">
                        <label>密码：</label>
                        <input type="password" name="password" id="password">
                    </p>
                    <p class="passwordtwo">
                        <label for="checkPassword">确认密码：</label>
                        <input type="password" name="passwordtwo" id="checkPassword">
                    </p>
                </div>
                <p class="know">
                    <span>
                        <input type="checkbox" name="confirm" id="confirm">
                        <label for="confirm">我已阅读注册相关条例</label>

                    </span>
                    <span>已有账号？<a href="login.html" id="href">点击登录</a></span>
                </p>

                <button id="regbtn">注册</button>
            </form>
        </div>
    </section>
    <footer>
        <div id="footer">
            <p>
                <img src="assets/images/footlogo.png" alt="">
            </p>
            <p>
            <ul>
                <li>隐私声明 服务协议 COOKIES Copyright © 2012-2021 华为终端有限公司 版权所有 粤ICP备19015064号|粤公网安备 44190002003939号</li>
                <li>增值电信业务经营许可证：粤B2-20190762|备案主体编号：44201919072182</li>
            </ul>
            </p>
        </div>
    </footer>
    <script src="../dist/js/jquery-3.5.1.min.js"></script>
    <script src="../dist/js/layer.js"></script>
    <script src="https://cdn.bootcss.com/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
    <script src="http://static.runoob.com/assets/jquery-validation-1.14.0/dist/jquery.validate.min.js"></script>
    <script src="http://static.runoob.com/assets/jquery-validation-1.14.0/dist/localization/messages_zh.js"></script>
    <script src="../dist/js/utilsa.js"></script>

    <script>
        $('#regbtn').click(function () {


            $.get('../loginform.php', $('#login').serialize(), 'json').then(res => {

                console.log(123)

            })


            return false  //取消默认设置
        })
        $("#login").validate({
            // 规则
            rules: {
                // key:表单域中的name名称
                username: {
                    // 规则
                    required: true,
                    minlength: 2,
                    maxlength: 5,
                    checkuser: true
                },
                password: {
                    // 规则
                    required: true,
                    minlength: 6,
                    maxlength: 10,
                    checkuser: true
                },
                passwordtwo: {
                    required: true,
                    minlength: 5,
                    equalTo: "#password"
                },
                phonenum: {
                    required: true,
                    number: true,
                    digits: true,
                    rangelength: [11, 11]
                }


            },
            // 验证失败后消息提示
            messages: {
                username: {
                    required: '账号或密码不能为空',
                    minlength: '长度不能少于2位',
                    maxlength: '长度不能多于5位'
                },
                password: {
                    required: '账号或密码不能为空',
                    minlength: '长度不能少于6位',
                    maxlength: '长度不能多于10位'
                },
                passwordtwo: {
                    required: "请确认密码",
                    minlength: "密码长度不能小于 5 个字符",
                    equalTo: "两次密码输入不一致"
                },
                phonenum: {
                    required: "请输入手机号",
                    number: "手机号格式错误",
                    digits: "手机号格式错误",
                    rangelength: "手机号必须为11位"
                }

            },

            // 验证失败后元素样式
            errorClass: 'shierror',
            // 验证通过后回调方法
            submitHandler: function (form) {
                $.post('login.php', $('#login').serialize(), null, 'json').then(res => {
                    layer.alert(res.msg, {}, function () {
                        layer.closeAll()
                        // console.log('aaaa')
                    })
                })
            }
        })







    </script>


    <script>
        $('#regbtn').click(function () {

            if (($("#newUser").val() == '') || ($("#phone").val() == '') || ($("#password").val() == '') || ($("#passwordtwo").val() == '')) {
                layer.alert("注册失败，信息未完善!")
            } else if ((!$(".know input[type='checkbox']").prop("checked"))) {
                layer.alert("请阅读并勾选注册相关条例!")
            }

            else {
                $.post('../loginform1.php', $('#login').serialize(), null, 'json').then(res => {


                    layer.alert(res.msg, {}, function () {
                        layer.closeAll()
                        console.log('aaaa')


                        if (res.type == "success") {

                            self.location = 'http://localhost:777/js0506/dist/login.html';
                        }

                    })

                })

            }


            return false  //取消默认设置
        })

    </script>

    <!-- <script>
        $('#regbtn').click(function () {



            $.post('../loginform1.php', $('#login').serialize(), null, 'json').then(res => {
                // alert(res.msg)
                layer.alert(res.msg, {}, function () {
                    layer.closeAll()
                    console.log('aaaa')


                    if (res.type == "success") {

                        self.location = '../0422/index.html';
                    }

                })
            })

            return false  //取消默认设置
        })

    </script> -->




</body>

</html>